using namespace std;
#include <iostream>
int n = 6;
// 直接插入排序算法
void insertsort (int a[],int n)
{
    int i,j;
    for ( i=2;i<=n;i++ )
    {
        if ( a[i]<a[i-1] )
        {
            a[0] = a[i];
            for ( j=i-1;a[0]<a[j];j-- )
                    a[j+1]=a[j];
            a[j+1]=a[0];
        }
    }
}
// 简单选择排序算法
void selectsort (int a[],int n)
{
    for ( int i=1;i<=n;i++ )
    {
        int min = i;
        for ( int j=i+1;j<=n;j++ )
        {            
            if ( a[j]<a[min] )
                min = j;
        }
        swap ( a[i],a[min] );
    }
}
// 冒泡排序算法
void bubblesort (int a[],int n)
{
    for ( int i=1;i<=n;i++ )
    {
        for ( int j=n;j>i;j-- )
            if ( a[j]<a[j-1] )
                swap ( a[j],a[j-1] );
    }
}
int main()
{
    int a[n+1] = {0,5,6,1,8,3,7};
    int b[n+1] = {0,5,6,1,8,3,7};
    int c[n+1] = {0,5,6,1,8,3,7};    
    cout << "未排序前序列为：" ;
    for ( int i=1;i<=n;i++ )
        cout << a[i] <<" ";
    cout <<endl;
    insertsort (a,n);
    cout << "直接插入排序结果：";
    for ( int i=1;i<=n;i++ )
        cout << a[i] <<" ";
    cout <<endl;
    selectsort (c,n);
    cout << "简单选择排序结果：";
    for ( int i=1;i<=n;i++ )
        cout << c[i] <<" ";
    cout <<endl;
    bubblesort (b,n);
    cout << "冒泡排序结果：";
    for ( int i=1;i<=n;i++ )
        cout << b[i] <<" ";
    cout <<endl;
}